package org.lejos.example;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import lejos.nxt.*;
/**
 *
 * @author alex
 */
public class LineFinder {
    private LightSensor lightSensor;
    private boolean done;
    public static void main(String[] args)
    {
        final LineFinder robot;
        robot = new LineFinder();
        robot.run();
    }
    public LineFinder()
    {
        final SensorPort lightPort;
        lightPort   = SensorPort.S3;
        lightSensor = new LightSensor(lightPort);
        lightSensor.setFloodlight(true);


    }
    public void run(){
        int distance;
        Motor.B.setSpeed(360);
        Motor.C.setSpeed(360);
        moveBackward();
        waitForLight(40);
    }
    
    private void moveBackward()
    {
        Motor.B.forward();
        Motor.C.forward();
    }
    private void exit()
    {
        synchronized(this)
        {
            done=true;
            notifyAll();
        }
    }

    private int waitForLight(final int max) {
        int light;

        do {
            light = lightSensor.readValue();
        } while (light>  max);

        return (light);
    }

   
}
